package com.gy.hsim.netty.client;

import java.nio.ByteBuffer;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import javax.swing.JOptionPane;

import com.gy.hsim.netty.proto.BserviceProto;
import com.gy.hsim.netty.proto.BserviceProto.BserviceEntity;
 
public class NettyClientHandler extends  SimpleChannelInboundHandler<Object> {
	 protected void channelRead(ChannelHandlerContext ctx, ByteBuf s) {
		System.out.println("server----->client1");
		//NettyClient.channel = ctx.channel();
		//JOptionPane.showMessageDialog(null, "服务器推送给你\r\n" + new String("ccc"), "接收到的消息",JOptionPane.ERROR_MESSAGE); 
	}

	@Override
	protected void messageReceived(ChannelHandlerContext ctx,
			Object o) throws Exception {
		// TODO Auto-generated method stub
		NettyClient.channel = ctx.channel();
		ByteBuffer byteBuf = ByteBuffer.wrap((byte[]) o);
		byte[] head = new byte[25];
		byteBuf.get(head, 0, 25);
		BserviceProto.BserviceEntity entity = BserviceProto.BserviceEntity.parseFrom(((byte[])o));
		
		System.out.println("server----->client2");
		JOptionPane.showMessageDialog(null, "服务器推送给你\r\n" + entity.getImSystem(), "接收到的消息",JOptionPane.ERROR_MESSAGE); 
	}
}
